import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from ddt import ddt, data
from getdata import GetData
from collections.abc import Mapping


@ddt
class LoginTest(unittest.TestCase):
    # 打开浏览器
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get("https://passport.ctrip.com/H5login/pc_login?BackUrl=https%3A%2F%2Fwww.ctrip.com%2F#ctm_ref=c_ph_login_buttom")

    def tearDown(self):
        self.driver.quit()


    @data(*GetData().getExcel())
    def test_login_success(self, testdata):
        self.driver.find_element(By.ID, "nloginname").send_keys(testdata["username"])
        self.driver.find_element(By.ID, "npwd").send_keys(testdata["password"])
        self.driver.find_element(By.ID, "nsubmit").click()
        self.assertEqual(self.driver.title, "首页")


    # def test_login_fail(self):
    #     self.driver.find_element(By.ID, "username").send_keys("编程大白")
    #     self.driver.find_element(By.ID, "password").send_keys("123456")
    #     self.driver.find_element(By.ID, "submit").click()
    #     self.assertEqual(self.driver.title, "首页")
